package com.polaris.live.popup

import android.content.Context
import android.text.Editable
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.common.R
import com.polaris.live.common.databinding.PopupAboutBinding
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.interface_bag.TextWatcherAdapter

/**
 * 关于我的弹窗
 *
 * @author Created by 长空 on 2023/10/25/004 17:21
 */
class AboutPopup(
    context: Context,
    private val mMessage: String,
    private val mOnAboutCallBack: ((about: String) -> Unit)
) : BottomPopupView(context) {

    private lateinit var mBinding: PopupAboutBinding
    private var mAbout = ""

    override fun getImplLayoutId(): Int {

        return R.layout.popup_about
    }

    override fun onCreate() {
        super.onCreate()

        mBinding = PopupAboutBinding.bind(popupImplView)

        mBinding.etName.addTextChangedListener(object : TextWatcherAdapter() {
            override fun afterTextChanged(s: Editable?) {
                mBinding.tvNum.text = "${s?.length}/140"
                mAbout = s.toString()
            }
        })

        mBinding.etName.setText(mMessage)
        mBinding.etName.setSelection(mMessage.length)

        mBinding.icBack.setOnSingleClickListener {
            dismiss()
        }

        mBinding.spSave.setOnSingleClickListener {
            mOnAboutCallBack.invoke(mAbout)
            dismiss()
        }
    }
}